package com.theatre.userservice.model.dto;

import com.theatre.userservice.model.entity.Script;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;

@Data
@Builder
public class ScriptDTO {

    @Schema(description = "剧本ID")
    private Long id;

    @Schema(description = "标题")
    private String title;

    @Schema(description = "作者")
    private String author;

    @Schema(description = "简介")
    private String description;

    @Schema(description = "剧本文件路径")
    private String contentFile;

    @Schema(description = "所属发行商ID")
    private Long publisherId;

    @Schema(description = "分类ID")
    private Long categoryId;

    @Schema(description = "价格")
    private BigDecimal price;

    @Schema(description = "状态：0待审核 1通过 2拒绝", allowableValues = {"0", "1", "2"})
    private Integer status;

    @Schema(description = "状态：0未售出 1已售出", allowableValues = {"0", "1"})
    private Integer sold;


    public static ScriptDTO fromEntity(Script script) {
        return ScriptDTO.builder()
                .id(script.getId())
                .title(script.getTitle())
                .description(script.getDescription())
                .contentFile(script.getContentFile())
                .publisherId(script.getPublisherId())
                .categoryId(script.getCategoryId())
                .price(script.getPrice())
                .status(script.getStatus())
                .sold(script.getSold())
//                .publisher(script.getPublisher()) // 如果你需要关联的 publisher 对象，可以在这里设置
//                .shop(script.getShop()) // 如果你需要关联的 shop 对象，可以在这里设置
//                .category(script.getCategory()) // 如果你需要关联的 category 对象，可以在这里设置
                .build();
    }

    public Script toEntity() {
        Script script = new Script();
        script.setId(this.getId());
        script.setTitle(this.getTitle());
        script.setDescription(this.getDescription());
        script.setContentFile(this.getContentFile());
        script.setPublisherId(this.getPublisherId());
        script.setCategoryId(this.getCategoryId());
        script.setPrice(this.getPrice());
        script.setStatus(this.getStatus());
        script.setSold(this.getSold());
        // 如果你需要关联的 publisher 对象，可以在这里设置
        // script.setPublisher(this.getPublisher());
        // 如果你需要关联的 shop 对象，可以在这里设置
        // script.setShop(this.getShop());
        // 如果你需要关联的 category 对象，可以在这里设置
        // script.setCategory(this.getCategory());
        return script;
    }
}
